package com.smartStatus.admin.log;

import com.smartStatus.log.config.LogConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @ClassName : LogAop
 * @Author : lby
 * @Date: 2020/12/8 16:20
 * @Description : 请求监控
 */
@Aspect
@Component
@Slf4j
public class LogAop {
    //    流水号
    private String serialNumber = String.valueOf(UUID.randomUUID());

//    @Autowired
//    private Sequence sequence;

    @Pointcut("execution(* com.smartStatus.*.controller..*.*(..))")
    public void webLog() {
    }

    /**
     * 方法执行前
     *
     * @param point
     * @throws Throwable
     */
    @Before("webLog()")
    public void doBefore(JoinPoint point) throws Throwable {
        //流水号
//        serialNumber = sequence.nextNo();
        LogConfiguration.doBefore(point, serialNumber);
    }

    /**
     * 方法执行结束
     *
     * @param ret
     * @throws Throwable
     */
    @AfterReturning(returning = "ret", pointcut = "webLog()")
    public void aa(Object ret) throws Throwable {
        LogConfiguration.doLast(ret, serialNumber);
    }
}
